clc
clear
data=xlsread('水肿与时间表2.xlsx');
for p=1:size(data,1) %遍历每一个人
    e=[]; %用于记录每次测试的误差
    tt=data(p,1);
    if tt>9
        tt=9;
    end
    type=data(p,2);
    for t=1:tt %遍历每一次测试
        if type==1
            [y]=hanshu1(data(p,t*2+1));
        elseif type==2
            [y]=hanshu2(data(p,t*2+1));
        elseif type==3
            [y]=hanshu3(data(p,t*2+1));
        else
            [y]=hanshu4(data(p,t*2+1));
        end
        e=[e abs(y-data(p,t*2+2))];
    end
    table(p,1)=mean(e);
end

%% 定义函数
function [y]=hanshu1(x)
p1    =  	-360.800751926447;
p2  =    	10528.3797933284;
p3   =   	-34754.457188382;
p4   =   	84161.4267909154;
p5   =   	-82853.9546961203;
p6    =  	41694.4655149236;
p7    =  	-11939.3076841018;
p8    =  	2025.46919387658;
p9    =  	-201.179472540657;
p10   =   	10.7904017496158;
p11    = -0.240871018892637;
y = p1+p2*log(x)+p3*(log(x)).^2+p4*(log(x)).^3+p5*(log(x)).^4+p6*(log(x)).^5+p7*(log(x)).^6+p8*(log(x)).^7+p9*(log(x)).^8+p10*(log(x)).^9+p11*(log(x)).^10;
end
function [y]=hanshu2(x)
    p1  =   	998.379184841163;
p2  =   	-10449.8048357094;
p3  =   	22366.8510798938;
p4   =  	9229.60407564166;
p5  =   	-39595.245993256;
p6=     	32139.0813444948;
p7   =  	-12740.5288632019;
p8   =  	2840.35319580306;
p9   =  	-362.822070945886;
p10 =    	24.8076096845318;
p11   =  	-0.70416790582444;
y = p1+p2*log(x)+p3*(log(x)).^2+p4*(log(x)).^3+p5*(log(x)).^4+p6*(log(x)).^5+p7*(log(x)).^6+p8*(log(x)).^7+p9*(log(x)).^8+p10*(log(x)).^9+p11*(log(x)).^10;
end
function [y]=hanshu3(x)
p1   =  	-32877.3945022987;
p2   =  	-42918.7151983012;
p3    = 	-69540.1866493174;
p4  =   	54966.5144400623;
p5    = 	-150841.300346862;
p6    = 	-27104.7018951224;
p7     =	-289180.606767868;
p8 =    	6100.8978828114;
p9  =   	-457282.656172485;
p10   =  	-553.812594383332;
p11   =  	-43114.3388117019;
p12  =   	44.5368774634045;
p13  =   	175085.878171785;
p14   =  	0.0253645618599475;
p15   =  	4813.36849450723;
p16  =   	-8.50209170426505E-6;
p17   = 	-1.14489967141217 ;
y = (p1+p3*x+p5*x.^2+p7*x.^3+p9*x.^4+p11*x.^5+p13*x.^6+p15*x.^7+p17*x.^8)./(1+p2*x+p4*x.^2+p6*x.^3+p8*x.^4+p10*x.^5+p12*x.^6+p14*x.^7+p16*x.^8);
end
function [y]=hanshu4(x)
p1  =   	-18.0329479910129;
p2    = 	-652.543871757392;
p3   =  	4636.6725804427;
p4 =    	2099.12873337132;
p5=     	-6703.41007812481;
p6   =  	4409.35168568665;
p7    = 	-1345.58285828921;
p8  =   	213.731635406168;
p9  =   	-17.0781654846846;
p10  =   	0.54198157044124;
y = p1+p2*log(x)+p3*(log(x)).^2+p4*(log(x)).^3+p5*(log(x)).^4+p6*(log(x)).^5+p7*(log(x)).^6+p8*(log(x)).^7+p9*(log(x)).^8+p10*(log(x)).^9;
end